<template>
	<view>
		<!-- 状态栏 -->
		<view class="statusBar" :style="'height:'+statusBarHeight+'px'"></view>
		<view class="myheader padding-sm  flex justify-between">
			<view class="font-sub-title">
				<text class="cuIcon-back margin-right-ssm" @click="back()"></text>
				体温监测
			</view>
			<text class="font-sub-title" @click="save()">保存</text>
		</view>
		<view class="cu-list menu">
			<view class="cu-item">
				<view class="content">
					体温监测
				</view>
				<view class="action">
					<switch class="blue" @change="open" :class="isopen?'checked':''" :checked="isopen"></switch>
				</view>
			</view>
			<view class="cu-item arrow">
				<view class="content">
					间隔时间
				</view>
				<view class="action text-gray">
					<picker mode="selector" :range="timeList" :value="timeIndex" @change="bindTimeChange">
						<view>{{timeList[timeIndex]}}</view>
					</picker>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					体温报警
				</view>
				<view class="action">
					<switch class="blue" @change="alarmOpen" :class="alarmIsopen?'checked':''" :checked="alarmIsopen"></switch>
				</view>
			</view>
			<view class="cu-item arrow">
				<view class="content">
					报警阈值
				</view>
				<view class="action text-gray">
					<picker mode="selector" :range="alarmList" :value="alarmIndex" @change="bindAlarmChange">
						<view>{{alarmList[alarmIndex]}}</view>
					</picker>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const bandSDK = uni.requireNativePlugin('BandSDK')
	var that;
	export default {
		data() {
			return {
				statusBarHeight: Vue.prototype.StatusBar,
				isopen:uni.getStorageSync("autoTemp")||false,
				alarmIsopen:uni.getStorageSync("alarmTemp")||false,
				timeList:['10min','20min','30min','40min','50min','60min'],
				timeIndex:uni.getStorageSync('tempTimeIndex')||0,
				alarmList:['37℃','38℃','39℃','40℃','41℃','42℃'],
				alarmIndex:uni.getStorageSync('tempAlarmIndex')||0,
			}
		},
		onLoad(){
			that =this;
		},
		methods: {
			back(){
				uni.navigateBack();
			},
			open(e){
				this.isopen = e.target.value
			},
			alarmOpen(e){
				this.alarmIsopen = e.target.value
			},
			bindTimeChange(e){
				this.timeIndex = e.target.value
			},
			bindAlarmChange(e){
				this.alarmIndex = e.target.value
			},
			save(){
				
				bandSDK.settingTemperatureMonitor({
					on_off:that.isopen,
					interval:that.timeList[that.timeIndex].substring(0,2)
				},res=>{
					if(res=='success'){
						uni.setStorageSync("autoTemp",that.isopen)
						uni.setStorageSync("tempTimeIndex",that.timeIndex)
						bandSDK.settingTemperatureAlarm({
							on_off:true,
							temp:that.alarmList[that.alarmIndex].substring(0,2)
						},res=>{
							if(res=='success'){
								uni.setStorageSync("alarmTemp",that.alarmIsopen)
								uni.setStorageSync("tempAlarmIndex",that.alarmIndex)
								uni.showToast({
									title:"保存成功"
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
